package reader;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-10-01
 * Time: 17:59
 */
public class FileReader_ {


    public static void FileReaderDemo1() throws IOException {
        try(FileReader fileReader = new FileReader("e://story.txt")){
            while(true){
                int readData = fileReader.read();
                if(readData==-1){
                    break;
                }
                System.out.printf("%c",readData);
            }
        }
    }

    public static void FileReaderDemo2() throws IOException {
        char[] buffer = new char[256];
        try(FileReader fileReader = new FileReader("e://story.txt")){
            while(true){
                int len = fileReader.read(buffer);
                if(len == -1){
                    break;
                }
                String str = new String(buffer,0,len);
                System.out.print(str);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        FileReaderDemo2();
    }
}
